package collection;
import java.util.ArrayList;
import java.util.List;
/**
 * List集合的演示:add()的重载、remove()的重载
 */
public class ListDemo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list); //list:[one, two, three, four, five]

        list.add(3,"six"); //在list下标为3的位置插入six
        System.out.println("list:"+list); //list:[one, two, three, six, four, five]
        //若add()时下标为最后一个元素的下一个位置，则相当于追加操作
        list.add(6,"seven"); //在list下标为6的位置插入seven
        System.out.println("list:"+list); //list:[one, two, three, six, four, five, seven]

        list.remove(2); //删除下标为2的元素----常规操作
        //String s = list.remove(2); //删除下标为2的元素，并将被删除元素返回给s
        //System.out.println(s); //three
        System.out.println("list:"+list); //list:[one, two, six, four, five, seven]
    }
}











